package com.hangim.pce.enums;

import com.fasterxml.jackson.annotation.JsonFormat;

/**
 * 用药时间段
 */
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum TimeStage {
    BEFORE_MEAL("BEFORE_MEAL", 1, "餐前"),
    MEAL("MEAL", 2, "用餐时"),
    AFTER_MEAL("AFTER_MEAL", 3, "餐后"),
    OTHER("OTHER", 0, "其他");
    // 类型
    private final String code;
    // 描述
    private final String desc;
    // 编号
    private final Integer num;

    TimeStage(final String code, final Integer num, final String desc) {
        this.code = code;
        this.desc = desc;
        this.num = num;
    }

    public static TimeStage getTimeStage(String code) {
        TimeStage[] ts = TimeStage.values();
        for (TimeStage t : ts) {
            if (t.getCode().equalsIgnoreCase(code)) {
                return t;
            }
        }
        return OTHER;
    }

    public static TimeStage getTimeStageByDesc(String desc) {
        TimeStage[] ts = TimeStage.values();
        for (TimeStage t : ts) {
            if (t.getDesc().contains(desc)) {
                return t;
            }
        }
        return OTHER;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public Integer getNum() {
        return num;
    }
}
